package com.itheima.config;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.convert.DataSizeUnit;
import org.springframework.boot.convert.DurationUnit;
import org.springframework.stereotype.Component;
import org.springframework.util.unit.DataSize;
import org.springframework.util.unit.DataUnit;
import org.springframework.validation.annotation.Validated;

import javax.validation.constraints.Max;
import java.time.Duration;
import java.time.temporal.ChronoUnit;

//@Component
@ConfigurationProperties(prefix ="servers")
@Data
@Validated//表示对这个bean开启校验
public class serverConfig {
    private String  ipAddress;
    private  int port;
    @Max(value = 888,message = "数值超出了最大值")
    private long timeout;

    //时间计量单位
    @DurationUnit(ChronoUnit.MINUTES)
    private Duration serverTimeout;

    //空间计量单位
    @DataSizeUnit(DataUnit.MEGABYTES)
    private DataSize dataSize;
}
